package buffer.io;

import java.io.*;
import java.net.Socket;
import java.util.Date;
 
/**
 * Created by zhengbin06 on 2017/2/2.
 */
public class Client {
  public static void main(String[] args) {
    String msg = "Client Data";
    try {
      Socket socket = new Socket("127.0.0.1", 9090);
 
      // 先写、再读
      PrintWriter printWriter = new PrintWriter(socket.getOutputStream());
      // 发送数据
      printWriter.println(msg);
      printWriter.flush();
      // 获得服务端返回的数据
      BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
      String line = bufferedReader.readLine();
      System.out.println("received from server: " + line + "\ttime=" + new Date().getTime());
      // 关闭资源
      printWriter.close();
      bufferedReader.close();
      socket.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}